﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UIScrollBarTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetRangeValue()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.AreEqual(0, scrollBar.RangeValue);
        }

        [TestMethod]
        public void ShouldGetIsRangeReadOnly()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.IsTrue(scrollBar.IsRangeReadOnly);
        }

        [TestMethod]
        public void ShouldGetRangeMinimum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.AreEqual(0, scrollBar.Minimum);
        }

        [TestMethod]
        public void ShouldGetRangeMaximum()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.AreEqual(0, scrollBar.Maximum);
        }

        [TestMethod]
        public void ShouldGetLargeChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.AreEqual(1, scrollBar.LargeChange);
        }

        [TestMethod]
        public void ShouldGetSmallChange()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITabItem tabItem2 = window.UITab("@AutomationId='tabControl1'").UITabItem("@Name='Tab 2'");
            tabItem2.Select();
            UIScrollBar scrollBar = tabItem2.UIDocument().UIScrollBar("@AutomationId='VerticalScrollBar'");
            Assert.AreEqual(0.1, scrollBar.SmallChange);
        }

        [TestMethod]
        public void ShouldGetAllScrollBars()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UIScrollBar> scrollBars = window.UIScrollBars();
            Assert.AreEqual(12, scrollBars.Count);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}